package com.ieheima.zixi;

import com.ieheima.demo.Student;

import java.io.*;
import java.util.ArrayList;

public class Demo03 {
    public static void main(String[] args) throws IOException, ClassNotFoundException {
        long start = System.currentTimeMillis();
        Student stu1 = new Student("刘备",34);
        Student stu2 = new Student("张飞",25);
        Student stu3 = new Student("关羽",32);
        ArrayList<Student> list = new ArrayList<>();
        list.add(stu1);
        list.add(stu2);
        list.add(stu3);
        ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("day13\\aaa\\c.txt"));
        oos.writeObject(list);
        oos.close();
        ObjectInputStream ois = new ObjectInputStream(new FileInputStream("day13\\aaa\\c.txt"));
        Object obj = ois.readObject();
        ois.close();
        ArrayList<Student> list1 = (ArrayList<Student>)obj;
        for (Student student : list1) {
            System.out.println(student);
        }
        long end = System.currentTimeMillis();
        System.out.println("程序运行了" + (end - start) + "毫秒！");
    }
}
